package controllers

import (
	"myblog/utils"

	beego "github.com/beego/beego/v2/server/web"
)

type SearchController struct {
	beego.Controller
}

type filenamedir struct {
	Filename string
	Filedir  string
}

func (this *SearchController) Post() {
	//获取搜索内容
	searchnr := this.GetString("Search")

	if searchnr != "" {
		//获取目录文件名
		postdir, _ := beego.AppConfig.String("postdir")
		postdir = utils.GetCurrentPath() + postdir
		filename := utils.SearchFile(postdir, searchnr)
		Filenames := make([]filenamedir, len(filename))
		for i, fname := range filename {
			Filenames[i].Filename = fname.Name()
			Filenames[i].Filedir = postdir + fname.Name()
		}
		this.Data["Filenames"] = Filenames
		this.TplName = "model/search.tpl"
		this.LayoutSections = make(map[string]string)
		this.LayoutSections["IndexHead"] = "model/ahead.tpl"
		this.LayoutSections["IndexNavbar"] = "model/navbar.tpl"
		this.LayoutSections["IndexNav"] = "model/nav.tpl"
		this.LayoutSections["IndexFoot"] = "model/afoot.tpl"
		this.Layout = "index.tpl"
	}

}
